package net.mywardrobes.manageclothescategory;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository("genericHibernateDao")
public class GenericHibernateDao {
	//EntityManager em;
	EntityManagerFactory emf;

	@PersistenceContext
	public void setEntityManager(EntityManager em) {
		// this.em = em;
	}

	@Autowired
	public void setEmf(EntityManagerFactory emf) {
		this.emf = emf;
//		this.em = emf.createEntityManager();
	}

	public Object save(Object in) {
		EntityManager em = emf.createEntityManager();
		em.getTransaction().begin();
		em.persist(in);
		em.getTransaction().commit();
		return in;
	}
}
